#ifndef CHATPAGE_H
#define CHATPAGE_H

#include <QListWidgetItem>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QWidget>
#include "messagebubble.h"
#include "userdata.h"
namespace Ui {
class ChatPage;
}

class ChatPage : public QWidget
{
    Q_OBJECT

public:
    explicit ChatPage(QWidget *parent = nullptr);
    ~ChatPage();
    void appendChatItem(QWidget *item);
    void prependChatItem(QWidget *item);
    void insertChatItem(QListWidgetItem *before, QWidget *item);
    void removeAllItem();

private:
    Ui::ChatPage *ui;
    QVBoxLayout *_message_list_layout;
    QWidget *_message_list;
    QScrollArea *_scrollArea;
    bool _isAppend;
    std::shared_ptr<FriendInfo> _friendInfo;

private:
    // 加载聊天记录
    void loadMessage();

public:
    // 添加新消息
    void addMessage(std::shared_ptr<TextChatData>);

private slots:
    void scrollBarMoved(int min, int max);
    void on_send_btn_clicked();

public:
    virtual bool eventFilter(QObject *watched, QEvent *event) override;
    void setFriendInfo(std::shared_ptr<FriendInfo>);
};

#endif // CHATPAGE_H
